﻿<UserControl x:Class="SampleApp.Controls.MotorSettingsControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:system="clr-namespace:System;assembly=mscorlib"
             xmlns:converters="clr-namespace:SampleApp.Converters"
             mc:Ignorable="d" >
	<UserControl.Resources>
		<converters:IndexToVisibilityConverter x:Key="IntToVis" />
		<converters:MotorValueTimerConverter x:Key="MotorTimerValue" />
		<converters:DoubleRoundedConverter x:Key="RoundValue" />
	</UserControl.Resources>
	<Grid x:Name="LayoutRoot">
		<Rectangle Fill="#ccc" Opacity=".85" />
		<Border Padding="15" Background="#111"  VerticalAlignment="Top">
			<StackPanel>
				<TextBlock
					Foreground="White"
					FontSize="32">
					<Run
						Text="Port " /><Run 
						Text="?" 
						x:Name="PortName" /><Run 
						Text=" - "/><Run 
						Text="?"
						x:Name="ObjectName"/><Run 
						Text=" Settings" />
				</TextBlock>

				<TextBlock
					Foreground="Gray"
					Margin="0, 0, 0, 5">
					Movement Style
				</TextBlock>
				<ComboBox
					Margin="0, 0, 0, 10" 
					x:Name="MovementStyle">
					<system:String>degrees</system:String>
					<system:String>time</system:String>
				</ComboBox>

				<Grid>
					<TextBlock 
						HorizontalAlignment="Left">
						<Run Text="Power"/>
					</TextBlock>
					<TextBlock 
						HorizontalAlignment="Right" 
						Text="{Binding Value, ConverterParameter=0, Converter={StaticResource RoundValue}, ElementName=PowerSlider}" />
				</Grid>
				<Slider 
					
					x:Name="PowerSlider"
					Value="0" 
					Minimum="-100"
					Maximum="100"
					SmallChange="1" 
					Foreground="Transparent" />

				<StackPanel 
					Visibility="{Binding SelectedIndex, ConverterParameter=0, Converter={StaticResource IntToVis}, ElementName=MovementStyle}">
					<Grid>
						<TextBlock 
							HorizontalAlignment="Left">
							<Run Text="Degrees"/>
						</TextBlock>
						<TextBlock 
							HorizontalAlignment="Right"
							Text="{Binding Value, ConverterParameter=0, Converter={StaticResource RoundValue}, ElementName=DegreeSlider}" />
					</Grid>
					<Slider 
						
						x:Name="DegreeSlider"
						Value="0" 
						Minimum="0"
						Maximum="720"
						Foreground="Transparent" />
				</StackPanel>

				<StackPanel 
					Visibility="{Binding SelectedIndex, ConverterParameter=1, Converter={StaticResource IntToVis}, ElementName=MovementStyle}">


					<Grid>
						<TextBlock 
							HorizontalAlignment="Left">
							<Run Text="seconds"/>
						</TextBlock>
						<TextBlock 
							HorizontalAlignment="Right"
							Text="{Binding Value, Converter={StaticResource MotorTimerValue}, ElementName=PowerTimerSlider}" />
					</Grid>
					<Slider
						x:Name="PowerTimerSlider"
						Value="5" />
				</StackPanel>
				<Button
					Margin="0, 10, 0, 0"
					Content="ok" 
					Click="RoundButton_Click" />
			</StackPanel>
		</Border>
	</Grid>
</UserControl>
